package com.tbit.main.config.rpc;

import com.tbit.common.utils.RpcSecurityUtil;
import com.tbit.manager.api.*;
import feign.RequestInterceptor;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import static com.tbit.common.constant.RpcConstants.RPC_HEADER_SECRET;
import static com.tbit.common.constant.RpcConstants.RPC_HEADER_TIME;

/**
 * rpc配置类
 *
 * @author <a href="mailto:chen.wutian@tbit.com.cn">BUGTian</a>
 * @since 2024/9/14
 */
@Configuration
@EnableFeignClients(clients = {AccountDayStatApi.class, TransactionOrderStatApi.class, UsageApi.class, UserApi.class,
        WorkbenchApi.class,UserAuthLogApi.class,StudentAuthApplyApi.class,AgentDepositVipApi.class,DepositApplyApi.class,
        GiftCardUserApi.class,RideCardApi.class,VipCardApi.class,MemberFeeApi.class, CouponApi.class, RefundServiceApi.class, QuickReplyApi.class,
        NoticeApi.class,TerControlApi.class,UserStatAPI.class,MaintainOAApi.class, ParkPointOAServiceApi.class, MachineOAApi.class, OrderOAApi.class, UserCardApi.class,
        OutAgeApi.class,MachineApi.class
})
public class RpcConfiguration {
    @Bean
    public RequestInterceptor requestInterceptor() {
        return requestTemplate -> {
            long t = System.currentTimeMillis();
            requestTemplate
                    .header(RPC_HEADER_SECRET, RpcSecurityUtil.encryption(t))
                    .header(RPC_HEADER_TIME, String.valueOf(t));
        };
    }

}
